package com.tedu.egweibo1.controller;

import com.tedu.egweibo1.base.response.JsonResult;
import com.tedu.egweibo1.base.response.StatusCode;
import com.tedu.egweibo1.mapper.UserMapper;
import com.tedu.egweibo1.mapper.WeiboMapper;
import com.tedu.egweibo1.pojo.dto.UserAddParam;
import com.tedu.egweibo1.pojo.entity.User;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("v1/user")
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @PostMapping("/add")
    public JsonResult insert(@RequestBody UserAddParam userAddParam){
        User user = new User();
        BeanUtils.copyProperties(userAddParam,user);
        user.setCreateTime(new Date());
        int num = userMapper.insert(user);
        return num>0?JsonResult.success():new JsonResult(StatusCode.OPERATION_FAILED);
    }

}
